<?php
error_reporting(E_ALL ^ E_NOTICE);

set_time_limit(0);
/*ini_set("memory_limit", "200M");
  mysql_connect("host=localhost dbname=hero  user=root  password=root")
   or die('Could not connect:'.mysql_last_error());
*/
$db_name="hero";  
 
$table_name="hero";  
 
$connection= @mysql_connect("localhost","root","root") or die(mysql_error());  
 
$db= @mysql_select_db($db_name,$connection) or die (mysql_error());  
 
$logdate =  mysql_query("SELECT DISTINCT date FROM `hero` where date > '2012-05-23'");

while($everylogdate = mysql_fetch_array($logdate))
{
      //游戏时间
    $gameTime_query = mysql_query("SELECT sum(todayGameTime) FROM hero where date ='$everylogdate[date]'");

    $gameTime = mysql_fetch_array($gameTime_query);

     //今日竞技场启动人数 
    $arenaTodayOpenNum_query = mysql_query("SELECT count(DISTINCT deviceid)  FROM hero where arenaTodayOpenTimes >0 and date ='$everylogdate[date]' ");
    $arenaTodayOpenNum = mysql_fetch_array($arenaTodayOpenNum_query);

     //今日竞技场启动次数
    $arenaTodayOpenTimes_query = mysql_query("SELECT sum(arenaTodayOpenTimes)  FROM hero where date ='$everylogdate[date]'");
    $arenaTodayOpenTimes = mysql_fetch_array($arenaTodayOpenTimes_query);

    //今日活跃人数
    $dayActivePesonrNum_query = mysql_query("SELECT count(DISTINCT deviceid)  FROM hero  where date ='$everylogdate[date]' and   date <> RegisterDate");
    $dayActivePesonrNum = mysql_fetch_array($dayActivePesonrNum_query);

    //今日竞技场游戏时间
    $arenaTodayGameTime_query = mysql_query("SELECT sum(arenaTodayGameTime) FROM hero where date ='$everylogdate[date]'");
    $arenaTodayGameTime = mysql_fetch_array($arenaTodayGameTime_query);

     //今日竞技场主页面发起挑战次数
    $arenaTodayLobbyChallengeTimes_query = mysql_query("SELECT sum(arenaTodayLobbyChallengeTimes) FROM hero where date ='$everylogdate[date]'");
    $arenaTodayLobbyChallengeTimes = mysql_fetch_array($arenaTodayLobbyChallengeTimes_query);

    //今日竞技场主页面发起挑战胜利次数
    $arenaTodayLobbyChallengeWinTimes_query = mysql_query("SELECT sum(arenaTodayLobbyChallengeWinTimes) FROM hero where date ='$everylogdate[date]'");
    $arenaTodayLobbyChallengeWinTimes = mysql_fetch_array($arenaTodayLobbyChallengeWinTimes_query);
    
    //今日昨日挑战页面发起挑战次数

    $arenaTodayReportChallengeTimes_query = mysql_query("SELECT sum(arenaTodayReportChallengeTimes) FROM hero where date ='$everylogdate[date]'");
    $arenaTodayReportChallengeTimes = mysql_fetch_array($arenaTodayReportChallengeTimes_query);
     
    //今日昨日挑战页面发起挑战胜利次数
    $arenaTodayReportChallengeWinTimes_query = mysql_query("SELECT sum(arenaTodayReportChallengeWinTimes) FROM hero where date ='$everylogdate[date]'");
    $arenaTodayReportChallengeWinTimes = mysql_fetch_array($arenaTodayReportChallengeWinTimes_query);

    //今日侦查人数
    $arenaTodayScoutNum_query = mysql_query("SELECT count(DISTINCT deviceid) FROM hero where arenaTodayScoutTimes >0 and date ='$everylogdate[date]'");
    $arenaTodayScoutNum = mysql_fetch_array($arenaTodayScoutNum_query);

    //今日侦查次数
    $arenaTodayScoutTimes_query = mysql_query("SELECT sum(arenaTodayScoutTimes) FROM hero where date ='$everylogdate[date]'");
    $arenaTodayScoutTimes = mysql_fetch_array($arenaTodayScoutTimes_query);

    //今日令牌获得数
    $arenaTodayGetBadges_query = mysql_query("SELECT sum(arenaTodayGetBadges) FROM hero where date ='$everylogdate[date]'");
    $arenaTodayGetBadges = mysql_fetch_array($arenaTodayGetBadges_query);

   
 $sql="REPLACE INTO report_nojailbreak_arena  (logdate,gameTime,arenaTodayOpenNum,arenaTodayOpenTimes,dayActivePesonrNum,arenaTodayGameTime,
                                               arenaTodayLobbyChallengeTimes,arenaTodayLobbyChallengeWinTimes,arenaTodayReportChallengeTimes,arenaTodayReportChallengeWinTimes,
                                               arenaTodayScoutNum,arenaTodayScoutTimes,arenaTodayGetBadges
                                        ) 
                  VALUES('$everylogdate[date]','$gameTime[0]','$arenaTodayOpenNum[0]','$arenaTodayOpenTimes[0]','$dayActivePesonrNum[0]','$arenaTodayGameTime[0]',
                         '$arenaTodayLobbyChallengeTimes[0]','$arenaTodayLobbyChallengeWinTimes[0]','$arenaTodayReportChallengeTimes[0]','$arenaTodayReportChallengeWinTimes[0]',
                         '$arenaTodayScoutNum[0]','$arenaTodayScoutTimes[0]','$arenaTodayGetBadges[0]'
                      
                          )";
$query= @mysql_query($sql,$connection) or die(mysql_error());  

}
?>
